/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mtetris;
import java.awt.*;

public class blocks {
    private int x=0, y=0;
    private Color Tcolor = new Color(123);
    private int [] xd = new int [4];
    private int [] yd = new int [4];
    public blocks (int x1, int y1, int x2, int y2, int x3 ,int y3, Color tc){
        xd[0]=x;xd[1]=x1;xd[2]=x2;xd[3]=x3;
        yd[0]=y;yd[1]=y1;yd[2]=y2;yd[3]=y3;
        Tcolor = tc;
        this.setPos();
    }
    public blocks (){
        xd[0]=0;xd[1]=0;xd[2]=0;xd[3]=0;
        yd[0]=0;yd[1]=0;yd[2]=0;yd[3]=0;
        Tcolor=Color.RED;
        this.setPos();
    }
    public void setBlocks (int x1, int y1, int x2, int y2, int x3 ,int y3, Color tc){
        xd[0]=x;xd[1]=x1;xd[2]=x2;xd[3]=x3;
        yd[0]=y;yd[1]=y1;yd[2]=y2;yd[3]=y3;
        Tcolor=tc;
    }
    public void setPos (int xp, int yp){
        x=xp;
        y=yp;
    }
    public void setPos (){
        x=145;
        y=120;
    }
    public int getX(){
        return x;
    }
    public int getY(){
        return y;
    }
    public void paintBlock (Graphics g){
        g.setColor(Tcolor);
        g.fillRect(x, y, 19, 19);
        g.fillRect(x+xd[1]*20, y+yd[1]*20, 19, 19);
        g.fillRect(x+xd[2]*20, y+yd[2]*20, 19, 19);
        g.fillRect(x+xd[3]*20, y+yd[3]*20, 19, 19);
    }
    public void setBlock (int [][]map, Color [][]Colormap){
        System.out.println((x+xd[1]*20-45)/20);
        System.out.println((y+yd[1]*20-120)/20);
        map[(x-45)/20][(y-120)/20]=1;
        map[(x+xd[1]*20-45)/20][(y+yd[1]*20-120)/20]=1;
        map[(x+xd[2]*20-45)/20][(y+yd[2]*20-120)/20]=1;
        map[(x+xd[3]*20-45)/20][(y+yd[3]*20-120)/20]=1;

        Colormap[(x-45)/20][(y-120)/20]=Tcolor;
        Colormap[(x+xd[1]*20-45)/20][(y+yd[1]*20-120)/20]=Tcolor;
        Colormap[(x+xd[2]*20-45)/20][(y+yd[2]*20-120)/20]=Tcolor;
        Colormap[(x+xd[3]*20-45)/20][(y+yd[3]*20-120)/20]=Tcolor;
    }
    public int testLeft (int [][] map){
        if(x<65||x+xd[1]<65||x+xd[2]<65||x+xd[3]<65)return 0;
        if(map[(x-45)/20-1][(y-120)/20]==1||
           map[(x+xd[1]*20-45)/20-1][(y+yd[1]*20-120)/20]==1||
           map[(x+xd[2]*20-45)/20-1][(y+yd[2]*20-120)/20]==1||
           map[(x+xd[3]*20-45)/20-1][(y+yd[3]*20-120)/20]==1)
            return 0;
        return 1;
    }
    public int testRight (int [][] map){
        if(x>205||x+xd[1]>205||x+xd[2]>205||x+xd[3]>205)return 0;
        if(map[(x-45)/20+1][(y-120)/20]==1||
           map[(x+xd[1]*20-45)/20+1][(y+yd[1]*20-120)/20]==1||
           map[(x+xd[2]*20-45)/20+1][(y+yd[2]*20-120)/20]==1||
           map[(x+xd[3]*20-45)/20+1][(y+yd[3]*20-120)/20]==1)
            return 0;
        return 1;
    }
    public int testDown (int [][] map){
        System.out.println(y);
        if(y>480||y+yd[1]*20>480||y+yd[2]*20>480||y+yd[3]*20>480)return 0;
        if(map[(x-45)/20][(y-120)/20+1]==1||
           map[(x+xd[1]*20-45)/20][(y+yd[1]*20-120)/20+1]==1||
           map[(x+xd[2]*20-45)/20][(y+yd[2]*20-120)/20+1]==1||
           map[(x+xd[3]*20-45)/20][(y+yd[3]*20-120)/20+1]==1)
            return 0;
        return 1;
    }
}
